<template>
    <fieldset>
        <legend>登入页</legend>
        用户名：
        <input type="text" v-model="username">
        <br>
        密码：
        <input type="password" v-model="password" @keydown.enter="handleClick">
        <br>
        <button @click="handleClick">登入</button>
    </fieldset>
</template>
<script setup>
import {ref} from "vue"
import * as api from "../../api/users"
import {useRouter} from "vue-router"

// 获取用户的信息和密码

let username=ref('')
let password=ref('')

let router=useRouter()

// 发起请求 
let handleClick=async()=>{
   let res=await api.loginApi(username.value,password.value)
//    console.log(res)
    // console.log(res.data.token)
    
    // 将令牌存到本地
    if(res.data.state){
        sessionStorage.setItem("h-token",res.data.token)

        // 登入之后跳转页面
        router.push('/')

    }else{
        alert(res.data.msg)
    }
    

   
}





</script>